package com.geor.gcv.core.model;

import java.util.LinkedHashMap;
import java.util.Map;

import org.opencv.core.Mat;

/**
 * 像素容器，用来统计像素的分布情况
 * @author lusongnan
 *
 */
public class PexContainer {

	private Mat mat;

	private int row;
	private int col;
	/** 统计每列的像素值*/
	private Map<Integer, Integer> maps = new LinkedHashMap<Integer, Integer>();

	public PexContainer(Mat mat) {
		this.mat = mat;
	}

	public PexContainer(int row, int col) {
		super();
		this.row = row;
		this.col = col;
	}

	public void setCol(int col) {
		this.col = col;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getCol() {
		return col;
	}

	public int getRow() {
		return row;
	}

	public int getWidth() {
		return (int) mat.size().width;
	}

	public int getHeight() {
		return (int) mat.size().height;
	}

	public Mat getMat() {
		return mat;
	}

	public void generatePdf(int start, int end) {
		row = getHeight();
		maps.clear();
		for (int i = start; i < end; i++) {
			int sum = 0;
			for (int j = 0; j < row; j++) {
				double pex = mat.get(j, i)[0];
				sum += pex;
			}
			maps.put(i, sum);
		}
	}

	// Generate pixel division figure
	public void generatePdf() {
		generatePdf(0, col);
	}

	public Map<Integer, Integer> getMaps() {
		return maps;
	}

	public void setMaps(Map<Integer, Integer> maps) {
		this.maps = maps;
	}

	public void clear() {
		maps.clear();
	}

}
